package com.tjbklx1.thread.chap03.practise05;

import com.tjbklx1.thread.chap03.demo01.Request;
import com.tjbklx1.thread.chap03.demo01.RequestQueue;

public class TalkThread extends Thread {

	private final RequestQueue input;
	private final RequestQueue output;

	public TalkThread(RequestQueue input, RequestQueue output, String name) {
		super(name);
		this.input = input;
		this.output = output;
	}

	@Override
	public void run() {
		System.out.println(Thread.currentThread().getName() + " Begin: ");

		for (int i = 0; i < 20; i++) {
			Request request = input.getRequest();

			System.out.println(Thread.currentThread().getName() + " gets "
					+ request);

			// modify
			Request response = new Request(request.getName() + "1");

			System.out.println(Thread.currentThread().getName() + " puts "
					+ response);

			output.putRequest(response);

		}

		System.out.println(Thread.currentThread().getName() + " Ends: ");
	}

}
